package com.li.springbootproject.spring.beanfactorypostprocessor;

import com.lidong.toolkit.constant.LogConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import java.util.UUID;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 3/12/2022 4:58 PM
 */
public class Car implements InitializingBean {

    private static final Logger logger = LoggerFactory.getLogger(Car.class);

    private String code = String.valueOf(UUID.randomUUID());

    /**
     * 引擎
     */
    private CarEngine engine;

    public Car() {
        logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car Constructor...");
        logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car engine not setting");
    }

    private void start() {
        logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car start...");
        engine.fire();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car initializingBean after propertieSet");
        if (engine == null) {
            logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car engine not setting, in initializingBean ");
        } else {
            logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car engine installed, in initializingBean");
            engine.fire();
        }
    }

    @PostConstruct
    public void postConstruct() {
        logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car postConstruct");
        if (engine == null) {
            logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car engine not setting, in postConstruct");
        } else {
            logger.info(LogConst.LOG_SUCCESS_PREFIX + "Car engine installed, in postConstruct");
        }
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public CarEngine getEngine() {
        return engine;
    }

    public void setEngine(CarEngine engine) {
        this.engine = engine;
    }
}
